/********************************************************************
	created:	2009/02/07
	created:	7:2:2009   23:55
	filename: 	qyThread.h
	author:		Xiong Jiayu
	copyright:  
	purpose:	
*********************************************************************/
#pragma once

#ifndef __QYTHREAD_H__
#define __QYTHREAD_H__

#include "qyThreadingCommon.h"
#include "../memsys/qyString.h"

/*
===========================================
class qyThread
===========================================
*/
class qyThread
{
public:
						qyThread();
	virtual				~qyThread();

	void				SetCoreId( uint32_t id );
	uint32_t			GetCoreId() const;

	void				SetStackSize( uint32_t s );
	uint32_t			GetStackSize() const;

	void				SetName( const qyString &name );
	const qyString &	GetName() const;

	void				Start();

	void				Stop();

	bool				IsRunning() const;

protected:
	virtual	void		Thread_DoWork();

private:
	static unsigned int WINAPI	Thread_Proc( void* self );

protected:
	HANDLE				m_threadHandle;
	uint32_t			m_coreID;
	uint32_t			m_stackSize;
};

//-----------------------------------------------------------------------
QY_INLINE void qyThread::SetCoreId( uint32_t id )
{
	m_coreID = id;
}

//-----------------------------------------------------------------------
QY_INLINE uint32_t qyThread::GetCoreId() const
{
	return m_coreID;
}

//-----------------------------------------------------------------------
QY_INLINE void qyThread::SetStackSize( uint32_t s )
{
	m_stackSize = s;
}

//-----------------------------------------------------------------------
QY_INLINE uint32_t qyThread::GetStackSize() const
{
	return m_stackSize;
}

//-----------------------------------------------------------------------
QY_INLINE bool qyThread::IsRunning() const
{
	return ( m_threadHandle != 0 );
}

#endif
